﻿using BepInEx;
using System;
using UnityEngine;
using HarmonyLib;
using UnityEngine.UI;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.EventSystems;
using System.Reflection;

namespace tiandiguixu.foring
{
    /// <summary>
    /// 百草园自动种植收割
    /// </summary>
    public partial class ForingMod
    {
         
        /// <summary>
        /// 点击丹方的时候，处理
        /// </summary>
        /// <param name="__instance"></param>
        /// <param name="eventData"></param>
        //[HarmonyPrefix, HarmonyPatch(typeof(Dojo_ItemSelectSlot), nameof(CollectBookSlot.OnPointerClick))]
        //public static void Dojo_ItemSelectSlot_OnPointerClick_Prefix(Dojo_ItemSelectSlot __instance, PointerEventData eventData)
        //{
        //    instance.Logger.LogInfo(__instance.GetSlotType());


        //    if (eventData.button == PointerEventData.InputButton.Left && __instance.GetSlotType() == Dojo_ItemSelectSlot.ItemSelectSlotType.丹方槽 && LianDan_LuziEditorPanel.instance.Luzi.isWuXingOrBiaoZhun && !LianDan_LuziEditorPanel.instance.Luzi.isWorking && LianDan_LuziEditorPanel.instance.Luzi.myStove != null)
        //    {
        //        var PelletFormulaStore = __instance.GetType().GetField("PelletFormulaStore", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as PelletFormulaStore;
        //        instance.Logger.LogInfo(PelletFormulaStore.FormulaName + "、" + PelletFormulaStore.Data?.Name + "、" + PelletFormulaStore.Data?.Items.Count);

        //        if (PelletFormulaStore.Data.Items.Count <= 0) return;

        //        //LianDan_LuziEditorPanel.instance.PlacePelletFormula(PelletFormulaStore);

        //        for (int i = 0; i < LianDan_LuziEditorPanel.instance.MaterialSlot.Length; i++)
        //        {
        //            LianDan_LuziEditorPanel.instance.MaterialSlot[i].Clear();
        //        }
        //        LianDan_LuziEditorPanel.instance.Luzi.RemoveYaoYin();
        //        LianDan_LuziEditorPanel.instance.Luzi.RemoveMaterials(0);
        //        LianDan_LuziEditorPanel.instance.Luzi.RemoveMaterials(1);
        //        LianDan_LuziEditorPanel.instance.Luzi.RemoveMaterials(2);
        //        LianDan_LuziEditorPanel.instance.Luzi.RemoveMaterials(3);
        //        LianDan_LuziEditorPanel.instance.CanStart = true;
        //        //LianDan_LuziEditorPanel.instance.FormulaSlot.SetPelletFormula(PelletFormulaStore);
        //        //LianDan_LuziEditorPanel.instance.Luzi.Store = PelletFormulaStore; 

        //        //foreach (var kv in LianDan_ItemListPanel.instance.MaterialSlots)
        //        //{
        //        //    instance.Logger.LogInfo(kv.Key + "  " + kv.Value.name + " " + kv.Value.GetNormalItem().GetItemName() + " " + kv.Value.GetNormalItem().GetNum());
        //        //}

        //        var df = PelletFormulaStore.Data.Items[0];
        //        //PelletFormulaStore.Data

        //        //PelletFormula pelletFormula = new PelletFormula(AllDictionary.Dic_PelletFormulaBook[PelletFormulaStore.FormulaName + "配方"]);
        //        if (!string.IsNullOrWhiteSpace(df.YaoYin))
        //        {
        //            if (LianDan_ItemListPanel.instance.MaterialSlots.ContainsKey(df.YaoYin))
        //            {
        //                LianDan_LuziEditorPanel.instance.PlaceMaterial(LianDan_ItemListPanel.instance.MaterialSlots[df.YaoYin].GetNormalItem());
        //            } 
        //        }
        //        for (int j = 0; j < df.Materials.Count; j++)
        //        {
        //            if (!string.IsNullOrWhiteSpace(df.Materials[j]) && LianDan_ItemListPanel.instance.MaterialSlots.ContainsKey(df.Materials[j]))
        //            {
        //                LianDan_LuziEditorPanel.instance.PlaceMaterial(LianDan_ItemListPanel.instance.MaterialSlots[df.Materials[j]].GetNormalItem(), j + 1, false);
        //            }
        //        }
        //        LianDan_LuziEditorPanel.instance.CaculateMaterialsNum();
        //        var SetStartBtn = LianDan_LuziEditorPanel.instance.GetType().GetMethod("SetStartBtn", BindingFlags.Instance | BindingFlags.NonPublic);
        //        SetStartBtn.Invoke(LianDan_LuziEditorPanel.instance, new object[] { LianDan_LuziEditorPanel.instance.Luzi.checkRequire() });
        //    }
        //}

     
    }
}
